# -*- coding:utf-8 -*-
# @Time: 2020/9/2 11:38
# @Author: liupengfei
# @File: filters.py

import django_filters

from .models import House, Room


class HouseFilter(django_filters.FilterSet):
    # title = django_filters.CharFilter(field_name='title', lookup_expr='icontains')

    class Meta:
        model = House
        fields = '__all__'


class RoomFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
    house = django_filters.CharFilter(method="filter_house")

    def filter_house(self, queryset, *args):
        house = House.get_instance_by_id(args[1])
        print(house)
        print(queryset.filter(house=house))
        return queryset.filter(house=house)

    class Meta:
        model = Room
        fields = '__all__'
